package com.woniu.map.controller;

import com.woniu.internalcommon.dto.ResponseResult;
import com.woniu.internalcommon.request.PointRequest;
import com.woniu.internalcommon.response.TraSearchResponse;
import com.woniu.internalcommon.response.TrackResponse;
import com.woniu.map.service.TrackService;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/track")
public class TrackController {

    @Resource
    private TrackService trackService;
    /**
     * 添加轨迹
     * @param tid
     * @param trname 需要去重
     * @return
     */
    @GetMapping ("/add")
    public ResponseResult<TrackResponse> addTrack(@RequestParam("tid") String tid
                            , @RequestParam("trname") String trname)
    {
//        {"errcode":20009,"errmsg":"EXISTING_ELEMENT","errdetail":"trname"}
        return  trackService.addTrack(tid, trname);
    }

    /**
     * 上传轨迹信息
     * @param pointRequest
     * @return
     */
    @PostMapping("/upload")
    public ResponseResult<String> uploadTrack(@RequestBody PointRequest pointRequest){

        return trackService.uploadTrack(pointRequest);
    }

    /**
     *
     * @param tid 必填 终端id
     * @param startTime 必填 上车时间戳
     * @param endTime 必填   行程结束时间戳
     * @return
     */
    @GetMapping("/trasearch")
    public ResponseResult<TraSearchResponse> traSearch(@RequestParam("tid") String tid,
                                                       @RequestParam("startTime") Long startTime ,
                                                       @RequestParam("endTime") Long endTime){
        return trackService.traSearch(tid, startTime, endTime);
    }

}
